package sr.myserver.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sr.myserver.commons.Result;
import sr.myserver.entity.SysUsers;
import sr.myserver.mapper.SysUsersMapper;
import sr.myserver.service.SysUsersService;
import sr.myserver.vo.SelectData;
import sr.myserver.vo.common.Basic;
import sr.myserver.vo.common.PageRequest;
import sr.myserver.vo.common.PageResponse;

import java.io.Serializable;

/**
 * 用户信息
 *
 * @author sirui
 **/
@Service
public class SysUsersServiceImpl implements SysUsersService {

    @Autowired
    SysUsersMapper sysUsersMapper;

    /**
     * 查询详情
     *
     * @param id 主键
     * @return 实体对象
     */
    @Override
    public SysUsers get(Serializable id) {
        return sysUsersMapper.selectById(id);
    }

    /**
     * 增加
     *
     * @param entity 请求参数
     * @return 响应码和响应消息
     */
    @Override
    public Basic.Response add(SysUsers entity) {
        sysUsersMapper.insert(entity);
        return Result.ok();
    }

    /**
     * 修改
     *
     * @param entity 请求参数
     * @return 响应码和响应消息
     */
    @Override
    public Basic.Response update(SysUsers entity) {
        sysUsersMapper.updateById(entity);
        return Result.ok();
    }

    /**
     * 删除
     *
     * @param id 主键
     * @return 响应码和响应消息
     */
    @Override
    public Basic.Response deleteById(Serializable id) {
        sysUsersMapper.deleteById(id);
        return Result.ok();
    }

    /**
     * 列表查询
     *
     * @param request 请求参数
     * @return 列表数据集合
     */
    @Override
    public PageResponse<SysUsers> queryTables(PageRequest request) {
        IPage<SysUsers> data = sysUsersMapper.queryTables(request.getPage(), request.getQueryData());
        return new PageResponse(data.getCurrent(), data.getSize(), data.getTotal(), data.getRecords());
    }

    /**
     * 下拉查询
     *
     * @param request 请求参数
     * @return 列表数据集合
     */
    @Override
    public PageResponse<SelectData> querySelect(PageRequest request) {
        IPage<SelectData> data = sysUsersMapper.querySelect(request.getPage(), request.getQueryData());
        return new PageResponse(data.getCurrent(), data.getSize(), data.getTotal(), data.getRecords());
    }
}

